package com.ewzj.bigdata.mvp.presenter

import android.app.Application
import android.support.v4.view.ViewPager
import android.view.View
import android.widget.TextView
import com.bigkoo.convenientbanner.ConvenientBanner
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.extensions.DelegatesExt
import com.ewzj.bigdata.mvp.contract.SplashContract
import com.ewzj.bigdata.mvp.ui.holder.SplashHolderView
import com.jess.arms.di.scope.ActivityScope
import com.jess.arms.mvp.BasePresenter
import me.jessyan.rxerrorhandler.core.RxErrorHandler
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
@ActivityScope
class SplashPresenter @Inject constructor(val mErrorHandler:RxErrorHandler,val application: Application,view:SplashContract.View,model:SplashContract.Model) :BasePresenter<SplashContract.Model,SplashContract.View>(model,view){
    val isfirst:Boolean by DelegatesExt.preference(application,AppKey.IS_FIRST,true);
    fun initBannner(banner: ConvenientBanner<Int>,tvfirst :TextView):Unit{
            val drawables: IntArray= intArrayOf(R.drawable.guide1,R.drawable.guide2,R.drawable.guide3);
            banner.isCanLoop=false;
            banner.setPages(object :CBViewHolderCreator<SplashHolderView>{
                override fun createHolder(): SplashHolderView {
                    return SplashHolderView()
                }
            },drawables.toList()).setPageIndicator(intArrayOf(R.drawable.shape_unselcircle_pageindicator,R.drawable.shape_sel_pageindicator))
                    .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL).onPageChangeListener = object :ViewPager.OnPageChangeListener{
                override fun onPageScrollStateChanged(state: Int) {

                }

                override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

                }

                override fun onPageSelected(position: Int) {
                    if (position==2){
                        tvfirst.visibility= View.VISIBLE
                    }else{
                        tvfirst.visibility= View.GONE
                    }
                }
            }
        }

}